/*
 * @Description:
 * @Author: fhw
 * @Date: 2022-08-02 14:39:45
 */
import { Body, Controller, Get, HttpCode, Post, Query, UseGuards } from '@nestjs/common'
import { ApiBearerAuth, ApiBody, ApiOperation, ApiQuery, ApiResponse, ApiTags } from '@nestjs/swagger'
import { ConnectedSocket } from '@nestjs/websockets'
import { SysMessageService } from '../sys_message/sys_message.service'
import { ChatUserFriendsService } from './chat_user_friends.service'
import { AddChatUserFriendsDto, ApplyForVerificationDto, DelChatUserFriendsDto, DeleteFriendsVerificationDto, GetUserFriendsListDto, UpdateRemarksDto } from './dto/chat_user_friends'
import { AuthGuard } from '@nestjs/passport';
import { throwHttp } from 'src/utlis'
@ApiBearerAuth() // swagger文档设置token
@Controller('chat-user-friends')
@ApiTags('用户好友')
export class ChatUserFriendsController {
  constructor(
    private readonly chatUserFriendsService: ChatUserFriendsService,
  ) {}
  @HttpCode(200)
  @Get('/getUserFriendsList')
  @ApiResponse({
    status: 200,
    description: '获取好友列表',
    type: GetUserFriendsListDto,
  })
  @ApiOperation({ summary: '获取好友列表', operationId: 'getUserFriendsList' })
  @UseGuards(AuthGuard('jwt'))//jwt策略，身份鉴权
  async getUserFriendsList(@Query() params: GetUserFriendsListDto) {
    try {
      return await this.chatUserFriendsService.getUserFriendsList(params)
    } catch (error) {
      console.log(error.message);
      throwHttp(error.message)
    }
  }

  @HttpCode(200)
  @Post('/addChatUserFriends')
  @ApiQuery({
    description: '添加好友',
    type: AddChatUserFriendsDto,
  })
  @ApiBody({ description: '添加好友', type: AddChatUserFriendsDto })
  @ApiOperation({ summary: '添加好友', operationId: 'addChatUserFriends'  })
  @UseGuards(AuthGuard('jwt'))//jwt策略，身份鉴权
  async addChatUserFriends(@Body() body: AddChatUserFriendsDto) {
    const { success, message } = await this.chatUserFriendsService.addChatUserFriends(body)
    if (!success) {
      return message
    }
    return '添加成功'
  }

  @HttpCode(200)
  @Post('/applyForVerification')
  @ApiQuery({
    description: '验证申请',
    type: ApplyForVerificationDto,
  })
  @ApiBody({ description: '验证申请', type: ApplyForVerificationDto })
  @ApiOperation({ summary: '验证申请', operationId: 'applyForVerification'  })
  @UseGuards(AuthGuard('jwt'))//jwt策略，身份鉴权
  async applyForVerification(@Body() body: ApplyForVerificationDto) {
    return await this.chatUserFriendsService.applyForVerification(body)
  }

  @HttpCode(200)
  @Post('/delChatUserFriends')
  @ApiQuery({
    description: '删除好友',
    type: DelChatUserFriendsDto,
  })
  @ApiBody({ description: '删除好友', type: DelChatUserFriendsDto })
  @ApiOperation({ summary: '删除好友', operationId: 'delChatUserFriends'  })
  @UseGuards(AuthGuard('jwt'))//jwt策略，身份鉴权
  async delChatUserFriends(@Body() body: DelChatUserFriendsDto) {
    return await this.chatUserFriendsService.delChatUserFriends(body)
  }

  @HttpCode(200)
  @Post('/updateRemarks')
  @ApiQuery({
    description: '更新好友备注',
    type: UpdateRemarksDto,
  })
  @ApiBody({ description: '更新好友备注', type: UpdateRemarksDto })
  @ApiOperation({ summary: '更新好友备注', operationId: 'updateRemarks'  })
  @UseGuards(AuthGuard('jwt'))//jwt策略，身份鉴权
  async updateRemarks(@Body() body: UpdateRemarksDto) {
    return await this.chatUserFriendsService.updateRemarks(body)
  }

  @HttpCode(200)
  @Get('/getFriendsInfo')
  @ApiResponse({
    status: 200,
    description: '获取好友信息',
    type: DelChatUserFriendsDto,
  })
  @ApiOperation({ summary: '获取好友信息', operationId: 'getFriendsInfo' })
  @UseGuards(AuthGuard('jwt'))//jwt策略，身份鉴权
  async getFriendsInfo(@Query() params: DelChatUserFriendsDto) {
    try {
      return await this.chatUserFriendsService.getFriendsInfo(params)
    } catch (error) {
      console.log(error.message);
      throwHttp(error.message)
    }
  }

  @HttpCode(200)
  @Post('/deleteFriendsVerification')
  @ApiQuery({
    description: '删除好友验证',
    type: DeleteFriendsVerificationDto,
  })
  @ApiBody({ description: '删除好友验证', type: DeleteFriendsVerificationDto })
  @ApiOperation({ summary: '删除好友验证', operationId: 'deleteFriendsVerification'  })
  @UseGuards(AuthGuard('jwt'))//jwt策略，身份鉴权
  async deleteFriendsVerification(@Body() body: DeleteFriendsVerificationDto) {
    return await this.chatUserFriendsService.deleteFriendsVerification(body)
  }
}
